package com.wuyou.designPatterns.decorator;

import com.wuyou.designPatterns.bridge.function.CountDisplay;

/**
 * FullBorder
 *
 * @Date 2024/9/26 14:15
 * @Author 无忧
 */
public class FullBorder extends Border{

    /**
     * 在生成实例时通过参数指定被装饰物
     *
     * @param display
     */
    protected FullBorder(Display display) {
        super(display);
    }

    @Override
    public int getColumns() {
        return 1 + display.getColumns() + 1;
    }

    @Override
    public int getRows() {
        return 1 + display.getRows() + 1;
    }

    @Override
    public String getRowText(int row) {
        if (row == 0) {
            return "+" + makeLine('-', display.getColumns()) + "+";
        } else if (row == display.getRows() + 1) {
            return "+" + makeLine('-', display.getColumns()) + "+";
        }else {
            return "|" + display.getRowText(row - 1) + "|";
        }
    }


    private String makeLine(char ch, int count){
        StringBuffer buf = new StringBuffer();
        for(int i=0; i<count; i++){
            buf.append(ch);
        }
        return buf.toString();
    }
}
